package main

import "fmt"

func main() {
	var i interface{}
	fmt.Printf("type: %T, value: %v\n", i, i)

	i = 1
	fmt.Println(i)

	i = "hello"
	fmt.Println(i)

	i = false
	fmt.Println(i)

	myfunc1(1)
	myfunc1("hello")
	myfunc1(false)

	myfunc2(1, "hello", false)

	any := make([]interface{}, 5)
	any[0] = 11
	any[1] = "hello world"
	any[2] = []int{11, 22, 33, 44}
	for _, value := range any {
		fmt.Println(value)
	}

	any1 := [...]interface{}{1, true, []int{11, 22, 33, 44}}
	for _, value := range any1 {
		fmt.Println(value)
	}

	typeAssert(11, "hello world", true)
}

func myfunc1(iface interface{}) {
	fmt.Println(iface)
}

func myfunc2(ifaces ...interface{}) {
	for _, iface := range ifaces {
		fmt.Println(iface)
	}
}

func typeAssert(i ...interface{}) {
	for index, value := range i {
		switch value.(type) {
		case int:
			fmt.Println("第", index+1, "个参数的类型是int")
		case string:
			fmt.Println("第", index+1, "个参数的类型是string")
		default:
			fmt.Println("第", index+1, "个参数的类型未知")
		}
	}
}
